package encore.portal.models;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

import encore.portal.config.PortletWindowConfig;

public class PageConfig implements Serializable {

	private String name;
	
	private String uri;
	
	private Collection portletIds;
	
	private int orderNumber;
	
	public PageConfig()
	{
		this.portletIds=new ArrayList();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getUri() {
		return uri;
	}

	public void setUri(String uri) {
		this.uri = uri;
	}

	public Collection getPortletIds() {
		return portletIds;
	}

	public void setPortletIds(Collection portletIds) {
		this.portletIds = portletIds;
	}

	public int getOrderNumber() {
		return orderNumber;
	}

	public void setOrderNumber(int orderNumber) {
		this.orderNumber = orderNumber;
	}
	
	
	@SuppressWarnings("unchecked")
	public void addPortlet(String contextPath,String portletName)
	{
		synchronized (portletIds) {
	      portletIds.add(PortletWindowConfig.createPortletId(contextPath, portletName, createPlacementId()));		
		}
	}
	
	public void removePortlet(String portletId)
	{
		portletIds.remove(portletId);
	}
 
	
	
	private String createPlacementId() {
		return getName().hashCode()+"|"+portletIds.size();
	}
   
	
}
